/*
 * Copyright (c) Huawei Technologies Co., Ltd. 2021-2022. All rights reserved.
 */

import { Unicode } from './unicode.js';

/**
 * 字符串判断工具
 * @since 2022/6/20
 */
export class JudgeUtil {
  public static isIgnoreChar(c: any) {
    return (
      typeof c === 'string' &&
      (c === '\t' || c === '\v' || c === '\f' || c === ' ' || c === '\u00A0' || c === '\uFEFF' || c === '\n' || c === '\r' || c === '\u2028' || c === '\u2029')
    );
  }

  public static isSpaceSeparator(c: any) {
    return typeof c === 'string' && Unicode.SPACE_SEPARATOR.test(c);
  }

  public static isIdStartChar(c: any) {
    return typeof c === 'string' && ((c >= 'a' && c <= 'z') || (c >= 'A' && c <= 'Z') || c === '$' || c === '_' || Unicode.ID_START.test(c));
  }

  public static isIdContinueChar(c: any) {
    return (
      typeof c === 'string' &&
      ((c >= 'a' && c <= 'z') ||
        (c >= 'A' && c <= 'Z') ||
        (c >= '0' && c <= '9') ||
        c === '$' ||
        c === '_' ||
        c === '\u200C' ||
        c === '\u200D' ||
        Unicode.ID_CONTINUE.test(c))
    );
  }

  public static isDigitWithoutZero(c: string) {
    return /[1-9]/.test(c);
  }

  public static isDigit(c: any) {
    return typeof c === 'string' && /[0-9]/.test(c);
  }

  public static isHexDigit(c: any) {
    return typeof c === 'string' && /[0-9A-Fa-f]/.test(c);
  }
}
